/* 
 * File:   function.h
 * Author: abadalya
 *
 * Created on November 25, 2011, 10:50 PM
 */

#ifndef FUNCTION_H
#define	FUNCTION_H

struct symbol_table;
struct expression;

/** To create linked list or expressions. */
struct expression_node {
    struct expression* data;
    struct expression_node* next;
};

/** Constructor */
extern struct expression_node* create_expression_node(struct expression*);

/** To create linked list of strings. */
struct string_node {
    char* data;
    struct string_node* next;
};

/** Constructor */
extern struct string_node* create_string_node(const char*);

/** lambda expression. */
struct lambda {
    // parameter count
    int paramc;
    // parameter names
    char** params;
    // number of expressions in body
    int bodyc;
    // parts of body
    struct expression** bodies;
};

/** Constructs lambda object */
extern struct lambda* create_lambda(struct string_node*,struct expression_node*);
/** Destroys lambda object */
extern void destroy_lambda(struct lambda*);
        
/**
 * Function application. It consists of lambda 
 * function pointer and expressions, which should 
 * be passed as arguments of function.
 */
struct funcall {
    // name of lambda symbol
    char* func;
    // number of arguments
    int argc;
    // actual arguments
    struct expression** args;
};

/** Constructs application to lambda object */
extern struct funcall* create_funcall(const char*, struct expression_node*);
/** Destroy lambda application object */
extern void destroy_funcall(struct funcall*);
/** Evaluate lambda application */
extern double evaluate_funcall(struct funcall*, struct symbol_table*);


#endif	/* FUNCTION_H */

